package cn.edu.cxcyzx.service.impl;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.edu.cxcyzx.algorithm.CalProgress_project;
import cn.edu.cxcyzx.entity.InsertReport;
import cn.edu.cxcyzx.entity.MyFile;
import cn.edu.cxcyzx.entity.Progress_project;
import cn.edu.cxcyzx.entity.Project;
import cn.edu.cxcyzx.service.MyFileService;
import cn.edu.cxcyzx.supervisor.DaoFit;

@Service("MyFileService")
public class MyFileServiceImpl implements MyFileService {
	
	@Resource
	public DaoFit daoFit;
	
	@Override
	public void insertFile(MyFile myFile,int projectId) {
		// TODO Auto-generated method stub
		daoFit.getMyFileDao().insertFile(myFile);
		Project project=new Project();
		project.setProjectId(projectId);
		switch (myFile.getFileType()) {
		case 4:
			//项目申报书
			break;
		case 5:
			//需求分析报告
			project.setProjectStatus(2);
			project.setAnalyseReport(myFile.getFileId());
			DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
			
			try {
				project.setAnalyseDate(format.parse(format.format(new Date())));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("update_pro:"+project.toString());
			daoFit.getProjectDao().update(project);
			//项目进度表插入数据
			daoFit.getProgress_projectDao().insertRecord(new Progress_project(projectId, CalProgress_project.CREATE_ANALYSE, "提交需求分析"));
			break;
		case 6:
			//项目报告
			System.out.println(new InsertReport(projectId,10,3,myFile.getFileId()).toString());
			project.setProjectStatus(10);
			project.setProjectReport(myFile.getFileId());
			daoFit.getProjectDao().update(project);
			break;
		case 7:
			//任务书
			
			break;
		default:
			break;
		}
		
		
	}

}
